package com.trh.dictionary.util;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * 工具类
 *
 * @author lixin
 * @date 2017-3-28
 */
public final class Utils {


    private Utils() {
    }


    public static <T> boolean in(T var, List<T> vars) {
        if (isNull(vars)) {
            return false;
        }
        for (Object temp : vars) {
            if (temp.equals(var)) {
                return true;
            }
        }

        return false;
    }

    public static boolean isEmpty(Collection<?> c) {
        if (isNull(c)) {
            return true;
        }
        return c.size() < 1 ? true : false;
    }

    public static boolean isEmpty(Map<?, ?> m) {
        if (isNull(m)) {
            return true;
        }
        return m.isEmpty();
    }

    public static boolean isEmpty(String s) {
        if (isNull(s)) {
            return true;
        }
        return s.trim().length() < 1 ? true : false;
    }

    public static <T> boolean isEmpty(T[] objs) {
        if (isNull(objs)) {
            return true;
        }
        return objs.length <= 0;
    }

    public static boolean isEqual(String s1, String s2) {
        if (isEmpty(s1) && isEmpty(s2)) {
            return true;
        }

        return s1 == null ? false : s1.equals(s2);
    }

    public static boolean isNotEmpty(Collection<?> c) {
        return !isEmpty(c);
    }

    public static boolean isNotEmpty(Map<?, ?> m) {
        return !isEmpty(m);
    }

    public static boolean isNotEmpty(String s) {
        return !isEmpty(s);
    }

    public static <T> boolean isNotEmpty(T[] objs) {
        return isNotNull(objs) && objs.length > 0;
    }


    public static boolean isNotNull(Object obj) {
        return obj != null ? true : false;
    }

    public static boolean isNull(Object obj) {
        return obj == null ? true : false;
    }


}
